<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/lightbox2/css/lightbox.min.css">
</head>
<style>
</style>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<th class="text-center" data-field="account">账号</th>
							<th class="text-center" data-field="name">姓名</th>
							<th class="text-center" data-field="idCard">身份证</th>
							<th class="text-center" data-field="tel">联系方式</th>
							<th class="text-center" data-field="time">申请时间</th>
							<th class="text-center" data-field="status">状态</th>
							<th class="text-center" data-field="action" data-formatter="actionFormatter" data-events="actionEvents">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">找书记详情</h4>
				</div>
				<div class="modal-body">
					<div class="input-group">
						<span class="input-group-addon">账号：</span> <input id="appAccount" type="text" class="form-control" aria-describedby="basic-addon1">
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">姓名：</span> <input id="appName" type="text" class="form-control" aria-describedby="basic-addon1">
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">身份证：</span> <input id="appNo" type="text" class="form-control" aria-describedby="basic-addon1">
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">联系方式：</span> <input id="appTel" type="text" class="form-control" aria-describedby="basic-addon1">
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">申请时间：</span> <input id="appDate" type="text" class="form-control" aria-describedby="basic-addon1">
					</div>
					<br>
					<div class="input-group">
						<span class="input-group-addon">内容：</span>
						<textarea id="appContent" class="form-control" rows="5" cols="30" style="resize: none;" readonly="readonly"></textarea>
					</div>
					<br>
				</div>
				<div class="modal-footer">
					<!-- 					<button type="button" class="btn btn-primary" onclick="adopt();">审核通过</button> -->
					<!-- 					<button type="button" class="btn btn-danger" onclick="showsm();">审核不通过</button> -->
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Large modal -->
	<div id="feedbackModal" class="modal fade bs-example-modal-lg" role="dialog">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">反馈窗口</h4>
				</div>
				<div class="modal-body">
					<div class="input-group">
						<span class="input-group-addon">反馈人：</span> <input type="text" class="form-control" value="${sessionScope.userAccount}" id="feedback_name">
					</div>
					<br />
					<div class="input-group">
						<span class="input-group-addon">内容：</span>
						<textarea style="width: 100%; height: 500px;" class="form-control" rows="30" id="column1_textarea" name="kindEditor_content"></textarea>
					</div>
				</div>
				<div class="modal-footer">
					<button id="feedbackBtn" class="btn btn-primary" onclick="feedback();">提交</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Large modal -->
	<div id="reasonModal" class="modal fade bs-example-modal-lg" role="dialog">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">审核失败窗口</h4>
				</div>
				<div class="modal-body">
					<div class="input-group">
						<span class="input-group-addon">操作人：</span> <input type="text" class="form-control" value="${sessionScope.userAccount}" id="feedback_name">
					</div>
					<br />
					<div class="input-group">
						<span class="input-group-addon">原因：</span>
						<textarea style="width: 100%; height: 500px;" class="form-control" rows="30" id="column2_textarea" name="kindEditor_content1"></textarea>
					</div>
				</div>
				<div class="modal-footer">
					<button class="btn btn-primary" onclick="reason();">提交</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/lightbox2/js/lightbox-plus-jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<!-- kindeditor 编辑器 -->
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/kindeditor.js"></script>
<script charset="utf-8" src="${pageContext.request.contextPath}/kindeditor-4.1.10/lang/zh_CN.js"></script>
<script>
	var selectId = "";
	var editor;
	var editor1;
	KindEditor.ready(function(K) {
		editor = K.create('textarea[name="kindEditor_content"]', {
			items : [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter',
					'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
					'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|',
					'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], //配置kindeditor编辑器的工具栏菜单项
			cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
			allowFileManager : true,
			uploadJson : '${pageContext.request.contextPath}/upload_img.do', //上传
			fileManagerJson : '${pageContext.request.contextPath}/mien_file_manager.do', // 文件管理
			filterMode : true, //是否启用过滤模式(编辑文本框中是否可以出现控件显示)
			htmlTags : {
				span : [ '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height' ],
				font : [ 'id', 'class', 'color', 'size', 'face', '.background-color' ],
				a : [ 'id', 'class', 'href', 'target', 'name' ],
				embed : [ 'id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess' ],
				img : [ 'id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border' ],
				'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight',
						'.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' ],
				pre : [ 'id', 'class' ],
				hr : [ 'id', 'class', '.page-break-after' ],
				'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : [ 'id', 'class' ],
				iframe : [ 'id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height' ]
			},
			allowFileManager : true,
			allowUpload : false, //允许上传图片
			imageUploadJson : '/saveImg', //服务端上传图片处理URI
			resizeType : 0,//使其不可以拖动 
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
				});
			},
			afterBlur : function() {
				this.sync();
			}
		});
	});

	KindEditor.ready(function(K) {
		editor1 = K.create('textarea[name="kindEditor_content1"]', {
			items : [ 'source', '|', 'undo', 'redo', '|', 'preview', 'print', 'template', 'code', 'cut', 'copy', 'paste', 'plainpaste', 'wordpaste', '|', 'justifyleft', 'justifycenter',
					'justifyright', 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', 'superscript', 'clearhtml', 'quickformat', 'selectall', '|',
					'fullscreen', '/', 'formatblock', 'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', '|',
					'image', 'multiimage', 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', 'anchor', 'link', 'unlink', '|', 'about' ], //配置kindeditor编辑器的工具栏菜单项
			cssPath : 'kindeditor-4.1.10/plugins/code/prettify.css',
			allowFileManager : true,
			uploadJson : '${pageContext.request.contextPath}/upload_img.do', //上传
			fileManagerJson : '${pageContext.request.contextPath}/mien_file_manager.do', // 文件管理
			filterMode : true, //是否启用过滤模式(编辑文本框中是否可以出现控件显示)
			htmlTags : {
				span : [ '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight', '.font-style', '.text-decoration', '.vertical-align', '.line-height' ],
				font : [ 'id', 'class', 'color', 'size', 'face', '.background-color' ],
				a : [ 'id', 'class', 'href', 'target', 'name' ],
				embed : [ 'id', 'class', 'src', 'width', 'height', 'type', 'loop', 'autostart', 'quality', '.width', '.height', 'align', 'allowscriptaccess' ],
				img : [ 'id', 'class', 'src', 'width', 'height', 'border', 'alt', 'title', 'align', '.width', '.height', '.border' ],
				'p,ol,ul,li,blockquote,h1,h2,h3,h4,h5,h6' : [ 'id', 'class', 'align', '.text-align', '.color', '.background-color', '.font-size', '.font-family', '.background', '.font-weight',
						'.font-style', '.text-decoration', '.vertical-align', '.text-indent', '.margin-left' ],
				pre : [ 'id', 'class' ],
				hr : [ 'id', 'class', '.page-break-after' ],
				'br,tbody,tr,strong,b,sub,sup,em,i,u,strike,s,del' : [ 'id', 'class' ],
				iframe : [ 'id', 'class', 'src', 'frameborder', 'width', 'height', '.width', '.height' ]
			},
			allowFileManager : true,
			allowUpload : false, //允许上传图片
			imageUploadJson : '/saveImg', //服务端上传图片处理URI
			resizeType : 0,//使其不可以拖动 
			afterCreate : function() {
				var self = this;
				K.ctrl(document, 13, function() {
					self.sync();
				});
				K.ctrl(self.edit.doc, 13, function() {
					self.sync();
				});
			},
			afterBlur : function() {
				this.sync();
			}
		});
	});

	function actionFormatter(value, row, index) {
		var check = "<button class='btn btn-primary btn-xs glyphicon glyphicon-pencil' onclick='show(\"" + row.id + "\");'>查看详情</button>";
		// 		var del = "<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' onclick='updateRecruit(\"" + row.id + ",-1,是否取消招募？" + "\");'>取消招募</button>";
		var btn = "";
		if (row.status == 0) {
			btn = "<button class='btn btn-success btn-xs glyphicon glyphicon-file' onclick='adopt(\"" + row.id
					+ "\");'>审核通过</button>&nbsp;<button class='btn btn-danger btn-xs glyphicon glyphicon-file' onclick='showsm(\"" + row.id + "\");'>审核不通过</button>&nbsp;" + check;
		} else if (row.status == 1) {
			btn = "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showFeedbackModal(\"" + row.id + ",0\");'>反馈</button>&nbsp;" + check;
		} else if (row.status == 2) {
			btn = "<button class='btn btn-success btn-xs glyphicon glyphicon-user' onclick='showFeedbackModal(\"" + row.id + ",1\");'>反馈查询</button>&nbsp;" + check;
		} else {
			btn = check;
		}
		return [ btn ].join('');
	}
	var table_dataset = [ {
		field : 'appAccount',
		align : 'center',
	}, {
		field : 'appName',
		align : 'center',
	}, {
		field : 'appNo',
		align : 'center',
	}, {
		field : 'appTel',
		align : 'center',
	}, {
		field : 'createTime',
		align : 'center',
		formatter : function timeFormatter(value, row, index) {
			return (new Date(row.createTime)).Format("yyyy-MM-dd hh:mm:ss");
		}
	}, {
		field : 'status',
		align : 'center',
		formatter : function statusFormatter(value, row, index) {
			var str = '';
			if (row.status == 0) {
				str = '待审核';
			} else if (row.status == 1) {
				str = '审核成功';
			} else if (row.status == 2) {
				str = '反馈完成';
			} else if (row.status == -2) {
				str = '审核失败';
			} else {
				str = '取消';
			}
			return str;
		}
	}, {
		align : 'center',
		formatter : actionFormatter,
	} ];

	$('#table').bootstrapTable(
			{
				url : "${pageContext.request.contextPath}/selectSecretarys",
				idField : "id",
				columns : table_dataset,
				striped : true, //是否显示行间隔色
				pagination : true, //是否显示分页
				pageSize : 10, //每页的记录行数
				pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
				// 		search : true, //是否显示搜索
				showRefresh : true,
				sidePagination : "server", //表示服务端请求  
				queryParamsType : "limit",
				toolbar : "<div  style='width:250px;float:left;margin-top:2px;'>" + "<select id='type' name='type' class='form-control' onchange='Querry()'>" + "<option value=''>全部</option>"
						+ "<option value='0'>待审核</option>" + "<option value='1'>审核成功</option>" + "<option value='2'>完成</option>" + "<option value='-2'>审核失败</option>" + "</select></div>"
						+ "<div class='input-group' style='width:250px;float:right;margin-top:2px;margin-left:20px;'>"
						+ "<input type='text' class='form-control' placeholder='请输入申请账号进行查询...' id='name' name='name'>"
						+ "<span class='input-group-btn'><button class='btn btn-default' type='button' onclick='Querry();'>查询</button></span></div>",
				queryParams : function queryParams(params) { //设置查询参数  
					var param = {
						offset : params.offset,
						limit : params.limit,
						name : $("#name").val(),
						type : $("#type").val()
					};
					return param;
				},
				icons : {
					paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
					paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
					refresh : 'glyphicon-refresh icon-refresh',
					toggle : 'glyphicon-list-alt icon-list-alt',
					columns : 'glyphicon-th icon-th',
					detailOpen : 'glyphicon-plus icon-plus',
					detailClose : 'glyphicon-minus icon-minus',
					"export" : 'glyphicon-export icon-share'
				},
				showExport : true,
				exportDataType : 'basic',
				exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ]
			});

	function show(id) {
		selectId = id;
		$.ajax({
			url : "${pageContext.request.contextPath}/selectSecretaryById",
			type : "post",
			data : {
				id : id
			},
			dataType : "json",
			success : function(data) {
				$("#picture").remove();
				var secretary = data.secretary;
				$("#appAccount").val(secretary.appAccount);
				$("#appName").val(secretary.appName);
				$("#appNo").val(secretary.appNo);
				$("#appTel").val(secretary.appTel);
				$("#appContent").val(secretary.appContent);
				$("#appDate").val((new Date(secretary.appDate)).Format("yyyy-MM-dd hh:mm:ss"));
				if (secretary.appPicture != null) {
					var div1 = '<div id="picture" style="height: 300px">';
					var div2 = '</div>';
					var appPictures = secretary.appPicture.split("★");
					var img = "";
					for (var i = 0; i < appPictures.length; i++) {
						//console.log(releaseImgs[i]);
						img += "<img class='cover-radius' src='http://" + window.location.host + "/upload/zhsq_xg/" + appPictures[i] + "' width='25%;' height='100%;' style='cursor: pointer;'>"
					}
					$("#appPicture").append(div1 + img + div2);
				}
				$('#modal').modal({
					backdrop : 'static',
					keyboard : false
				});
			}
		});
	}

	function adopt(id) {
		layer.confirm("是否要审核通过？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/updateSecretary",
				type : "post",
				data : {
					id : id,
					status : '1'
				},
				dataType : "json",
				success : function(data) {
					if (data.result == 1) {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							$("#table").bootstrapTable('refresh');
						}, 500);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function showsm(id) {
		selectId = id;
		$('#reasonModal').modal({
			backdrop : 'static',
			keyboard : false
		});
	}

	function reason() {
		var reasonContent = $('#column2_textarea').val();
		if (reasonContent == '') {
			layer.alert("请填写审核失败原因！");
			return false;
		}
		if(editor1.isEmpty()){
			layer.alert("请填写审核失败原因!");
			return false;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/updateSecretary",
			type : "post",
			data : {
				id : selectId,
				status : '-2',
				auditReason : reasonContent
			},
			dataType : "json",
			success : function(data) {
				if (data.result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
					}, 500);
					$("#reasonModal").modal("hide");
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
			},
			error : function() {
				layer.msg('系统繁忙，请稍后再试!', {
					icon : 5,
					time : 800
				});
			}
		});
	}

	function showFeedbackModal(param) {
		selectId = param.split(",")[0];
		$.ajax({
			url : "${pageContext.request.contextPath}/selectSecretaryById",
			type : "post",
			data : {
				id : selectId
			},
			dataType : "json",
			success : function(data) {
				var secretary = data.secretary;
				editor.html(secretary.feedbackContent);
				if (param.split(",")[1] == 0) {
					$("#feedbackBtn").show();
					$('#feedback_name').attr("disabled", "disabled");
					editor.readonly(false);
				} else {
					$("#feedbackBtn").hide();
					$('#feedback_name').removeAttr("disabled");
					editor.readonly(true);
				}
				$('#feedbackModal').modal({
					backdrop : 'static',
					keyboard : false
				});
			}
		});
	}

	function feedback() {
		var feedbackContent = $('#column1_textarea').val();
		if (feedbackContent == '') {
			layer.alert("请填写反馈信息！");
			return false;
		}
		if(editor.isEmpty()){
			layer.alert("请填写反馈信息!");
			return false;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/feedbackSecretary",
			type : "post",
			data : {
				id : selectId,
				feedbackContent : feedbackContent,
				status : '2'
			},
			dataType : "json",
			success : function(data) {
				if (data.result == 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
					}, 500);
					$("#feedbackModal").modal("hide");
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
			}
		});
	}

	function Querry() {
		$("#table").bootstrapTable('refresh');
	}
</script>
</html>
